<!DOCTYPE HTML>
<html lang="en">
<head>
<title>ControlMove - Syntax &amp; Usage | AutoHotkey</title>
<meta name="description" content="The ControlMove command moves or resizes a control." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>ControlMove</h1>

<p>Moves or resizes a control.</p>

<pre class="Syntax"><span class="func">ControlMove</span>, Control, X, Y, Width, Height <span class="optional">, WinTitle, WinText, ExcludeTitle, ExcludeText</span></pre>
<h2>Parameters</h2>
<dl>

  <dt>Control</dt>
  <dd><p>Can be either ClassNN (the classname and instance number of the control) or the control's text, both of which can be determined via Window Spy. When using text, the matching behavior is determined by <a href="SetTitleMatchMode.htm">SetTitleMatchMode</a>. If this parameter is blank, the target window's topmost control will be used.</p>
    <p>To operate upon a control's HWND (window handle), leave the <em>Control</em> parameter blank and specify <code>ahk_id %ControlHwnd%</code> for the <em>WinTitle</em> parameter (this also works on hidden controls even when <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> is Off). The HWND of a control is typically retrieved via <a href="ControlGet.htm#Hwnd">ControlGet Hwnd</a>, <a href="MouseGetPos.htm">MouseGetPos</a>, or <a href="DllCall.htm">DllCall()</a>.</p></dd>

  <dt>X, Y</dt>
  <dd><p>The X and Y coordinates  (in pixels) of the upper left corner of <em>Control</em>'s new location, which can be <a href="../Variables.htm#Expressions">expressions</a>. If either coordinate is blank, <em>Control</em>'s position in that dimension will not be changed. The coordinates are relative to the upper-left corner of the <em>Control</em>'s parent window; <a href="ControlGetPos.htm">ControlGetPos</a> or Window Spy can be used to determine them.</p></dd>

  <dt>Width, Height</dt>
  <dd><p>The new width and height of <em>Control</em> (in pixels), which can be <a href="../Variables.htm#Expressions">expressions</a>. If either parameter is blank or omitted, <em>Control</em>'s size in that dimension will not be changed.</p></dd>

  <dt>WinTitle</dt>
  <dd><p>A window title or other criteria identifying the target window. See <a href="../misc/WinTitle.htm">WinTitle</a>.</p></dd>

  <dt>WinText</dt>
  <dd><p>If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if <a href="DetectHiddenText.htm">DetectHiddenText</a> is ON.</p></dd>

  <dt>ExcludeTitle</dt>
  <dd><p>Windows whose titles include this value will not be considered.</p></dd>

  <dt>ExcludeText</dt>
  <dd><p>Windows whose text include this value will not be considered.</p></dd>

</dl>

<h2>Error Handling</h2>
<p><span class="ver">[v1.1.04+]</span>: This command is able to throw an exception on failure. For more information, see <a href="Catch.htm#RuntimeErrors">Runtime Errors</a>.</p>
<p><a href="../misc/ErrorLevel.htm">ErrorLevel</a> is set to 1 if there was a problem or 0 otherwise.</p>
<h2>Remarks</h2>
<p>To improve reliability, a delay is done automatically after every use of this command. That delay can be changed via <a href="SetControlDelay.htm">SetControlDelay</a>.</p>
<p>Window titles and text are case sensitive. Hidden windows are not detected unless <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> has been turned on.</p>

<h2>Related</h2>
<p><a href="ControlGetPos.htm">ControlGetPos</a>, <a href="WinMove.htm">WinMove</a>, <a href="SetControlDelay.htm">SetControlDelay</a>, <a href="Control.htm">Control</a>, <a href="ControlGet.htm">ControlGet</a>, <a href="ControlGetText.htm">ControlGetText</a>, <a href="ControlSetText.htm">ControlSetText</a>, <a href="ControlClick.htm">ControlClick</a>, <a href="ControlFocus.htm">ControlFocus</a>, <a href="ControlSend.htm">ControlSend</a></p>
<h2>Examples</h2>
<div class="ex" id="ExControlMoveTimer">
<p><a href="#ExControlMoveTimer">#1</a></p>
<pre>SetTimer, ControlMoveTimer
InputBox, OutputVar, My Input Box
return

ControlMoveTimer:
IfWinNotExist, My Input Box
    return
<em>; Otherwise the above set the &quot;last found&quot; window for us:</em>
SetTimer, ControlMoveTimer, Off
WinActivate
ControlMove, OK, 10, , 200  <em>; Move the OK button to the left and increase its width.</em>
return</pre>
</div>

</body>
</html>
